package com.baizhi.cmfzmanager.service.impl;

import com.baizhi.cmfzmanager.dao.GuruDao;
import com.baizhi.cmfzmanager.entity.Guru;
import com.baizhi.cmfzmanager.service.GuruService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class GuruServiceImpl implements GuruService {

    private Logger logger= LoggerFactory.getLogger(GuruServiceImpl.class);

    @Autowired
    private GuruDao guruDao;
    @Override
    public Map getGurus(int page, int rows) {
        logger.info("分页查新大师开始");
        int start=(page-1)*rows;
        IPage<Guru> iPage = new Page<>(start,rows);
        IPage<Guru> guruIPage = guruDao.selectPage(iPage, null);
        Map map = new HashMap();
        map.put("total",guruIPage.getTotal());
        map.put("rows",guruIPage.getRecords());
        logger.warn("分页查新大师结束");
        return map;
    }

    @Override
    public List<Guru> getAll() {
        logger.info("查询所有大师开始");
        List<Guru> guruList = guruDao.selectList(null);
        logger.error("查询所有大师结束");
        return guruList;
    }

    @Override
    public void update(Guru guru) {
        logger.info("修改大师信息service方法");
        guruDao.update(guru);
    }

    @Override
    public void add(Guru guru) {
        logger.info("添加大师方法service");
        guruDao.add(guru);
    }

    @Override
    public void delete(int[] ids) {
        logger.info("删除选中");
        guruDao.delete(ids);
    }

    @Override
    public void addlist(List<Guru> list) {
        logger.info("开始导入表格开始；插入数据");
        for (Guru guru:list) {
            guruDao.add(guru);
        }
        logger.info("数据插入结束");
    }
}
